package InetAdress;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class InputAdress {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket=new ServerSocket(9999);
        System.out.println("等待连接！");
        Socket socket=serverSocket.accept();
        System.out.println(socket.getClass());

        //读取字符并显示
        InputStream inputStream= socket.getInputStream();//使用字节流接收
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream));
        System.out.println(bufferedReader.readLine());//输出内容
        //bufferedReader.readLine();//写出结束

        //输入字符内容
        BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bufferedWriter.write("hello,client");//回复hello，clent
        bufferedWriter.newLine();//写入结束
        bufferedWriter.flush();//手动刷新


        //必须关闭流和socket
        bufferedWriter.close();
        bufferedReader.close();
        socket.close();
        serverSocket.close();
        inputStream.close();
    }
}
